//
//  JYServiceController.m
//  JYFarm
//
//  Created by 花花 on 2017/10/12.
//  Copyright © 2017年 花花. All rights reserved.
//

#import "JYServiceController.h"
#import "JYMineMenuCell.h"
@interface JYServiceController ()

@property(nonatomic)NSArray *titleArr;
@property(nonatomic)NSArray *imgArr;
@end

static NSString *const JYServiceCellID = @"JYServiceCellID";
@implementation JYServiceController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initUI];
    
}
- (void)initUI{
    
    self.title = @"联系客服";
    self.titleArr = @[@"全国客服热线：400-600-6656",@"客服经理专线：13666668888"];
    self.imgArr = @[@"mine_customer_service",@"mine_customer_service"];
    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, 240)];
    
    [self.tableView registerClass:[JYMineMenuCell class] forCellReuseIdentifier:JYServiceCellID];
    UIImageView *imgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"login_logo"]];
    imgView.center = headerView.center;
    [headerView addSubview:imgView];
    self.tableView.tableHeaderView = headerView;
 
    self.tableView.tableFooterView = [UIView new];
    
}
#pragma mark - <UITableViewDataSource,UITableViewDelegate>

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
       return [self.titleArr count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    JYMineMenuCell *cell = [tableView dequeueReusableCellWithIdentifier:JYServiceCellID];
    
        cell.titleLabel.text = [self.titleArr safeObjectAtIndex:indexPath.row];
        cell.titleLabel.textColor = k3Color;
        cell.titleLabel.font = kFont(13);
         cell.arrowImg.hidden = YES;
        cell.iconImage.image =[UIImage imageNamed:[self.imgArr safeObjectAtIndex:indexPath.row]];

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.row == 0) {
        [self telmessage:ServicePhone1 serverice:@"是否联系客服"];
    }else{
        [self telmessage:ServicePhone2 serverice:@"是否联系客服经理"];
    }
    

}
- (void)telmessage:(NSString *)telmessage serverice:(NSString *)serverice{
    
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:serverice  message:telmessage delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [alertView showAlertWithHandler:^(NSInteger buttonIndex) {
        if (buttonIndex ==1) {
            NSString *phone = [telmessage stringByReplacingOccurrencesOfString:@"-" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, telmessage.length)];
            NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",phone]];
            [[UIApplication sharedApplication] openURL:url];
        }
    }];
}



@end
